package App.Repository;

import App.Model.Account.CrmWebLogin;
import App.Model.Project.CrmProjectStage;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Column;
import javax.persistence.Id;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xw on 2019/4/26.
 */

@Repository
public class QRCodeRepository extends BaseRepository {

    @Transactional
    public int insertWebLoginRecord(String recid) {

        int _result = 0;
        String _strSql = " insert into crm_web_login(recid) values(:recid)  ";

        Map<String, Object> _params = new HashMap<>();
        _params.put("recid", recid);
        _result = updateEntity(_strSql, _params);
        return _result;
    }

    @Transactional
    public int updateToken(String recid, String token,int userid) {

        int _result = 0;
        String _strSql = "update crm_web_login set token=:token,userid=:userid where recid=:recid ";

        Map<String, Object> _params = new HashMap<>();
        _params.put("recid", recid);
        _params.put("token", token);
        _params.put("userid", userid);
        _result = updateEntity(_strSql, _params);
        return _result;
    }


    public List<CrmWebLogin> getToken(String recid) {

        String _strSql = " select * from crm_web_login where recid=:recid order by createtime desc";

        Map<String, Object> _params = new HashMap<>();
        _params.put("recid", recid);
        List<CrmWebLogin> _result = getEntitys(_strSql, _params, CrmWebLogin.class);
        return _result;
    }


    @Transactional
    public int confirmReWebLogin(String key) {

        int _result = 0;
        String _strSql = "update crm_web_login set isconfirmed=true where recid=:recid ";

        Map<String, Object> _params = new HashMap<>();
        _params.put("recid", key);
        _result = updateEntity(_strSql, _params);
        return _result;
    }

    public List<CrmWebLogin> isWebReLoginConfirmed(String recid) {

        String _strSql = " select recid,token,isconfirmed,userid from crm_web_login where recid=:recid ";
        Map<String, Object> _params = new HashMap<>();
        _params.put("recid", recid);
        List<CrmWebLogin> _result = getEntitys(_strSql, _params, CrmWebLogin.class);
        return _result;
    }

    @Transactional
    public int setWebReLoginUnConfirmed(String recid) {

        String _strSql = " update crm_web_login set isconfirmed=false  where recid=:recid ";
        Map<String, Object> _params = new HashMap<>();
        _params.put("recid", recid);
        int _result = updateEntity(_strSql, _params);
        return _result;
    }


}
